package com.custom.view;

import com.custom.R;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

public class MyViewB extends LinearLayout {
	public MyViewB(Context context) {
		this(context, null);
	}

	public MyViewB(Context context, AttributeSet attrs) {
		super(context, attrs);
		int resouceId = -1;
		TypedArray typedArray = context.obtainStyledAttributes(attrs,
				R.styleable.MyViewB);
		TextView tv = new TextView(context);
		EditText et = new EditText(context);
		int N = typedArray.getIndexCount();
		for (int i = 0; i < N; i++) {
			int attr = typedArray.getIndex(i);
			switch (attr) {
			case R.styleable.MyViewB_Oriental:
				resouceId = typedArray.getInt(R.styleable.MyViewB_Oriental, 0);
				this.setOrientation(resouceId == 1 ? LinearLayout.HORIZONTAL
						: LinearLayout.VERTICAL);
				break;

			case R.styleable.MyViewB_Text:
				resouceId = typedArray.getResourceId(R.styleable.MyViewB_Text,
						0);
				tv.setText(resouceId > 0 ? typedArray.getResources().getText(
						resouceId) : typedArray
						.getString(R.styleable.MyViewB_Text));
				break;
			}
		}
		
		addView(tv);
		addView(et);
		typedArray.recycle();
	}
}